<template>
  <right>
    <template slot="card">
      <CardGroup @tabChange="tabChange" ref="cardGroup"></CardGroup>
    </template>
    <template slot="detail">
      <keep-alive>
        <router-view>
            <!-- 这里是会被缓存的视图组件，比如 Home！ -->
        </router-view>
      </keep-alive>
    </template>
  </right>
</template>
<script>
  // 此组件是通话模块的根组件
  import right from '@/components/ui-modules/right-layout/RightLayout'
  import CardGroup from './CallCardGroup.vue'
  import ContactSummary from '@/components/public-modules/contact-summary'
  import {isHasFunc} from '@/utils/m7Utils'
  export default {
    name: 'call',
    data () {
      return {
        currentRoute: '',
        preRoute: ''
      }
    },
    components: {
      right,
      CardGroup,
      ContactSummary
    },
    computed: {
    },
    watch: {
      $route (to, from) {
        if (to.fullPath.indexOf('cdr_call') > -1) { // 只要是来电的操作，都记录当前操作的路由，tab切换回来电时，能默认选中上一次操作的卡片
          this.preRoute = to.fullPath
        }
      }
    },
    methods: {
      tabChange (tabType) {
        if (tabType === 'cdr_call') { // tab切换回来电时，能默认选中上一次操作的卡片
          this.$nextTick(() => {
            this.$refs.cardGroup.pushCdrCallRoute(this.preRoute || '/index/call/cdr_call')
          })
        }
      }
    },
    beforeRouteLeave (to, from, next) { // 离开通话模块时记住当前路由
      this.currentRoute = from.fullPath
      next()
    },
    beforeRouteEnter (to, from, next) { // 再次进入通话模块时把之前的路由还回去
      next(vm => {
        if (to.query && to.query.flag && to.query.flag === 'notify') { // 当前模块不是call模块时的来电跳转
          vm.$router.push({path: to.fullPath})
        } else if (to.query && to.query.status && to.query.status === 'autoqc') { // 当前模块不是call模块时的智能质检跳转
          vm.$router.push({path: to.fullPath})
        } else if (vm.currentRoute) {
          vm.$router.push({path: vm.currentRoute})
          let tabName = vm.currentRoute.split('/')[3]
          if (tabName) {
            vm.$store.commit('BLANK', tabName) // 设置通话的空白页
          }
          if (to.path === '/index/call/cdr_all/callExport') {
            vm.$nextTick(() => {
              vm.$router.push({path: to.path})
            })
          }
        }
        if (!vm.currentRoute) {
          vm.$store.commit('BLANK', 'cdr_call') // 设置通话的空白页
        }
      })
    }
  }
</script>
<style lang="stylus" scoped>
.call
  background #efefef
  color $cf-level2
li
  width 439px
  height 79px
  border-bottom 1px solid #eee
.cust-info
  min-height 141px
  max-width 200px
  width 100%
.cust-tab
  height:100%
</style>
